//哲学家就餐问题解法



Semphore forks = {1,1,1,1,1};
Semphore allowedEatNums(4);

void philosopher(int id){
	for(int i=0;i<3;i++){
		think();
		//解决可能的死锁问题
		//
		SemphoreWait(allowedEatNums);
		SemphoreWait(forks[id]);
		SemphoreWait(forks[(id+1)%5]);
		eat();
		SemphoreSignal(forks[(id+1)%5]);
		SemphoreSignal(forks[id]);
		SemphoreSignal(allowedEatNums);
	}
	eat();
}
